// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    text: '盒马云超市来啦!0门槛包邮!上海外环内...1/1',
    marqueePace: 1,//滚动速度
    marqueeDistance: 0,//初始滚动距离
    size: 14,
    orientation: 'left',//滚动方向
    interval: 20, // 时间间隔
    adUrl: '../../images/notice.png',
    navShopping:[],
    backColor:[
      '#BE8159',
      '#A1B1CA',
      '#FFC793',
      '#C2D971',
      '#F5CB8D',
      '#83D7F4',
      '#FF9292',
      '#2EC4C6',
      '#8599B9',
      '#F3D24C'
    ],
    classifyList:[]
  },
  onShow: function () {
    // 页面显示
    var that = this;
    var length = that.data.text.length * that.data.size;//文字长度
    var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
    that.setData({
      length: length,
      windowWidth: windowWidth,
    });
    that.runMarquee();// 水平一行字滚动完了再按照原来的方向滚动
  },
  runMarquee: function () {
    var that = this;
    var interval = setInterval(function () {
      //文字一直移动到末端
      if (-that.data.marqueeDistance < that.data.length) {
        that.setData({
          marqueeDistance: that.data.marqueeDistance - that.data.marqueePace,
        });
      } else {
        clearInterval(interval);
        that.setData({
          marqueeDistance: that.data.windowWidth
        });
        that.runMarquee();
      }
    }, that.data.interval);
  },
  init(){
    wx.request({
      url: 'https://www.fastmock.site/mock/9f01a220d9987817dad2292eba073289/hema/goodsSorts', 
      success:(res)=> {
        console.log(res.data.data)
        this.setData({
          navShopping:res.data.data
        })
      }
    });
  },
  // goGoodsList:function(e){
  //   console.log(e.currentTarget.dataset.goodsid)
  //   let goodsId=e.currentTarget.dataset.goodsid;
  //   wx.navigateTo({
  //     url: '/pages/goodsList?id='+goodsId
  //   })
  // },
  //页面初始化时
  onLoad(options) {
    this.init()
    wx.request({
      url: 'https://www.fastmock.site/mock/9f01a220d9987817dad2292eba073289/hema/sortItems',
      success:(res)=>{
        console.log(res.data.data)
        this.setData({
          classifyList:res.data.data
        })
      }
    })
  }
})
